﻿#region Legal notice
/*
 * This file is part of EPPLib.
 * Copyright 2010, 2011 
 * Gianluca Esposito (info@gianlucaesposito.it)
 * ----------------------------------------------------------------------------
 * EPPLib is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 * 
 * EPPLib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with Nome-Programma; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EPPLib.Messages;
using EPPLib.Objects;

namespace EPPWebMVC.Controllers
{
    public class SampleController : BaseController
    {
        [Authorize]
        public ActionResult Index()
        {
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult CreateContact()
        {
            MessageContainer container = new MessageContainer();
            
            CreateContactMessage contactMessage = new CreateContactMessage();
            contactMessage.ContactID = "mr0001";
            contactMessage.PostalInfo.Name = "Mario Rossi";
            contactMessage.PostalInfo.Address.Address[0] = "via Moruzzi, 1";
            contactMessage.PostalInfo.Address.City = "Pisa";
            contactMessage.PostalInfo.Address.District = "PI";
            contactMessage.PostalInfo.Address.PostalCode = "56124";
            contactMessage.PostalInfo.Address.CountryCode = "IT";
            contactMessage.Phone.Number = "+39.050315";
            contactMessage.Phone.Internal = "2111";
            contactMessage.Fax.Number = "+39.0503152593";
            contactMessage.Email = "mario.rossi@esempio.it";

            CreateExtendedContactMessage extendedContactMessage = new CreateExtendedContactMessage();
            extendedContactMessage.ConsentForPublishing = true;

            container.Command = contactMessage;
            container.Extension = extendedContactMessage;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Create;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult CreateContactRegistrant()
        {
            MessageContainer container = new MessageContainer();

            CreateContactMessage contactMessage = new CreateContactMessage();
            contactMessage.ContactID = "mr0001";
            contactMessage.PostalInfo.Name = "Mario Rossi";
            contactMessage.PostalInfo.Organization = "Mario Rossi";
            contactMessage.PostalInfo.Address.Address[0] = "via Moruzzi, 1";
            contactMessage.PostalInfo.Address.City = "Pisa";
            contactMessage.PostalInfo.Address.District = "PI";
            contactMessage.PostalInfo.Address.PostalCode = "56124";
            contactMessage.PostalInfo.Address.CountryCode = "IT";
            contactMessage.Phone.Number = "+39.050315";
            contactMessage.Phone.Internal = "2111";
            contactMessage.Fax.Number = "+39.0503152593";
            contactMessage.Email = "mario.rossi@esempio.it";

            CreateExtendedContactMessage extendedContactMessage = new CreateExtendedContactMessage();
            extendedContactMessage.ConsentForPublishing = true;
            extendedContactMessage.Registrant.EntityType = 1;
            extendedContactMessage.Registrant.NationalityCode = "IT";
            extendedContactMessage.Registrant.TaxCode = "RSSMRA64C14G702Q";

            container.Command = contactMessage;
            container.Extension = extendedContactMessage;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Create;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }


        [Authorize]
        public ActionResult TestSerialization()
        {
            CheckContactResponseMessage response = new CheckContactResponseMessage();
            CheckContactData temp = new CheckContactData();
            temp.Info.ID = "1";
            temp.Info.IsAvailable = true;
            response.Response.Data.CheckContact.Data.Add(temp);
            ViewData["TEMP"] = response.Serialize();
            return View();
        }

        [Authorize]
        public ActionResult CreateDomain()
        {
            MessageContainer container = new MessageContainer();
            CreateDomainMessage domainMessage = new CreateDomainMessage();
            domainMessage.Name = "esempio.it";
            domainMessage.AuthInfo.Password = "22fooBAR";

            HostObject host1 = new HostObject();
            host1.Name = "ns1.esempio.it";
            host1.Address.Address = "193.205.245.70";
            host1.Address.AddressType = HostAddressObject.AddressTypes.IPv4;

            HostObject host2 = new HostObject();
            host2.Name = "ns2.esempio.it";
            host2.Address.Address = "193.205.245.77";
            host2.Address.AddressType = HostAddressObject.AddressTypes.IPv4;

            domainMessage.HostInfo.Hosts.Add(host1);
            domainMessage.HostInfo.Hosts.Add(host2);

            domainMessage.Registrant.Code = "mr0001";
            domainMessage.Contacts.Add(new ContactCodeObject("cl8013", ContactCodeObject.ContactTypes.Admin));
            domainMessage.Contacts.Add(new ContactCodeObject("mb8015", ContactCodeObject.ContactTypes.Tech));

            container.Command = domainMessage;
            container.Extension = null;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Create;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult CreateDomainNoSubHost()
        {
            MessageContainer container = new MessageContainer();
            CreateDomainMessage domainMessage = new CreateDomainMessage();
            domainMessage.Name = "paperino.it";
            domainMessage.AuthInfo.Password = "22fooBAR";

            HostObject host1 = new HostObject();
            host1.Name = "ns1.esempio.it";

            HostObject host2 = new HostObject();
            host2.Name = "ns.dominio.org";

            domainMessage.HostInfo.Hosts.Add(host1);
            domainMessage.HostInfo.Hosts.Add(host2);

            domainMessage.Registrant.Code = "mm-001";
            domainMessage.Contacts.Add(new ContactCodeObject("mm-001", ContactCodeObject.ContactTypes.Admin));
            domainMessage.Contacts.Add(new ContactCodeObject("mm-001", ContactCodeObject.ContactTypes.Tech));

            container.Command = domainMessage;
            container.Extension = null;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Create;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult UpdateContact()
        {
            MessageContainer container = new MessageContainer();
            UpdateContactMessage message = new UpdateContactMessage();
            message.ContactID = "mr0001";
            message.AddInfo.Status.ClientDeletedProhibited = true;
            message.ChangeInfo.Email = "info@esempio.it";
            message.ChangeInfo.Phone.Number = "+39.05863152111";

            container.Command = message;
            container.Extension = null;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Update;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult UpdateContact2()
        {
            MessageContainer container = new MessageContainer();
            UpdateContactMessage message = new UpdateContactMessage();
            message.ContactID = "mr0001";

            UpdateExtendedContactMessage extendedMessage = new UpdateExtendedContactMessage();
            extendedMessage.ConsentForPublishing = true;

            container.Command = message;
            container.Extension = extendedMessage;

            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Update;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult UpdateDomain()
        {
            MessageContainer container = new MessageContainer();
            UpdateDomainMessage message = new UpdateDomainMessage();
            message.Name = "esempio.it";
            message.AddInfo.Status.ClientDeletedProhibited = true;
            message.AddInfo.Contact.Code = "mak21";
            message.AddInfo.Contact.Type = ContactCodeObject.ContactTypes.Tech;
            message.AddInfo.Hosts.Hosts.Add(new HostObject("ns3.esempio.it", "193.205.245.73", HostAddressObject.AddressTypes.IPv4));
            message.RemoveInfo.Hosts.Hosts.Add(new HostObject("ns1.esempio.it"));

            container.Command = message;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Update;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult UpdateDomain2()
        {
            MessageContainer container = new MessageContainer();
            UpdateDomainMessage message = new UpdateDomainMessage();
            message.Name = "esempio.it";
            message.AddInfo.Hosts.Hosts.Add(new HostObject("ns3.esempio.it", "193.205.245.73", HostAddressObject.AddressTypes.IPv4));
            message.RemoveInfo.Hosts.Hosts.Add(new HostObject("ns1.esempio.it"));

            container.Command = message;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Update;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult UpdateDomain3()
        {
            MessageContainer container = new MessageContainer();
            UpdateDomainMessage message = new UpdateDomainMessage();
            message.Name = "esempio.it";
            message.AddInfo.Hosts.Hosts.Add(new HostObject("ns3.esempio.it", "193.205.245.73", HostAddressObject.AddressTypes.IPv4));
            message.RemoveInfo.Hosts.Hosts.Add(new HostObject("ns3.esempio.it"));

            container.Command = message;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Update;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult UpdateDomain4()
        {
            MessageContainer container = new MessageContainer();
            UpdateDomainMessage message = new UpdateDomainMessage();
            message.Name = "esempio.it";
            message.ChangeInfo.AuthInfo.Password = "NEW2BARfoo";
            message.ChangeInfo.Registrant.Code = "mr002";

            container.Command = message;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Update;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult RestoreDomain()
        {
            MessageContainer container = new MessageContainer();
            UpdateDomainMessage message = new UpdateDomainMessage();
            message.Name = "esempio.it";

            UpdateExtendedDomainMessage extendedMessage = new UpdateExtendedDomainMessage();
            
            container.Command = message;
            container.Extension = extendedMessage;
            
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Update;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult TransferDomainRequest()
        {
            MessageContainer container = new MessageContainer();
            TransferDomainMessage message = new TransferDomainMessage();
            message.Name = "esempio.it";
            message.AuthInfo.Password = "22fooBAR";

            container.Command = message;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Transfer;
            container.Operation = MessageContainer.Operations.TransferRequest;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult TransferDomainTrade()
        {
            MessageContainer container = new MessageContainer();
            TransferDomainMessage message = new TransferDomainMessage();
            message.Name = "esempio.it";
            message.AuthInfo.Password = "22fooBAR";

            TransferExtendedDomainMessage extendedMessage = new TransferExtendedDomainMessage();
            extendedMessage.TradeInfo.NewAuthInfo.Password = "NEW2fooBAR";
            extendedMessage.TradeInfo.NewRegistrant.Code = "m1001";

            container.Command = message;
            container.Extension = extendedMessage;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Transfer;
            container.Operation = MessageContainer.Operations.TransferRequest;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult TransferDomainCancel()
        {
            MessageContainer container = new MessageContainer();
            TransferDomainMessage message = new TransferDomainMessage();
            message.Name = "esempio.it";
            message.AuthInfo.Password = "22fooBAR";

            container.Command = message;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Transfer;
            container.Operation = MessageContainer.Operations.TransferCancel;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult TransferDomainApprove()
        {
            MessageContainer container = new MessageContainer();
            TransferDomainMessage message = new TransferDomainMessage();
            message.Name = "esempio.it";
            message.AuthInfo.Password = "22fooBAR";

            container.Command = message;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Transfer;
            container.Operation = MessageContainer.Operations.TransferApprove;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult TransferDomainReject()
        {
            MessageContainer container = new MessageContainer();
            TransferDomainMessage message = new TransferDomainMessage();
            message.Name = "esempio.it";
            message.AuthInfo.Password = "22fooBAR";

            container.Command = message;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Transfer;
            container.Operation = MessageContainer.Operations.TransferReject;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult DeleteDomain()
        {
            MessageContainer container = new MessageContainer();
            DeleteDomainMessage message = new DeleteDomainMessage();
            message.Name = "esempio.it";

            container.Command = message;
            container.Extension = null;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Delete;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult CheckContact()
        {
            MessageContainer container = new MessageContainer();
            CheckContactMessage message = new CheckContactMessage();

            message.IDs.Add("mm001");
            message.IDs.Add("mb001");
            message.IDs.Add("cl001");
            message.IDs.Add("bb001");

            container.Command = message;
            container.Extension = null;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Check;

            ViewData["__REQUEST"] = container.ToString();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult ContactInfo()
        {
            MessageContainer container = new MessageContainer();
            InfoContactMessage message = new InfoContactMessage();

            message.ID = "MISSING001";

            container.Command = message;
            container.Extension = null;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Info;

            ViewData["__REQUEST"] = container.ToString();

            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult CheckDomain()
        {
            MessageContainer container = new MessageContainer();
            CheckDomainMessage message = new CheckDomainMessage();

            message.Names.Add("esempio1.it");
            message.Names.Add("esempio2.it");
            message.Names.Add("esempio3.it");

            container.Command = message;
            container.Extension = null;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Check;

            ViewData["__REQUEST"] = container.ToString();

            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult InfoDomain()
        {
            MessageContainer container = new MessageContainer();
            InfoDomainMessage message = new InfoDomainMessage();

            message.DomainName.Name = "esempio.it";

            container.Command = message;
            container.Extension = null;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Info;

            ViewData["__REQUEST"] = container.ToString();

            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult InfoDomainAuthInfo()
        {
            MessageContainer container = new MessageContainer();
            InfoDomainMessage message = new InfoDomainMessage();

            message.DomainName.Name = "esempio.it";
            message.AuthInfo.Password = "22fooBAR";

            container.Command = message;
            container.Extension = null;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Info;

            ViewData["__REQUEST"] = container.ToString();

            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult DomainTransferQuery()
        {
            MessageContainer container = new MessageContainer();
            DomainTransferQueryMessage message = new DomainTransferQueryMessage();

            message.DomainName = "esempio.it";
            message.AuthInfo.Password = "22fooBAR";

            container.Command = message;
            container.Extension = null;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Transfer;
            container.Operation = MessageContainer.Operations.Query;

            ViewData["__REQUEST"] = container.ToString();

            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult PollRequest()
        {
            MessageContainer container = new MessageContainer();
            container.Command = new PollRequestMessage();
            container.Extension = null;
            container.ClientTransactionID = "ABC-12345";
            container.Type = MessageContainer.CommandTypes.Poll;
            container.Operation = MessageContainer.Operations.Request;
            ViewData["__REQUEST"] = container.ToString();

            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult PollAcknownledgment()
        {
            MessageContainer container = new MessageContainer();
            container.Command = new PollAcknowledgmentMessage();
            container.Extension = null;
            container.ClientTransactionID = "ABC-12345";
            container.MessageID = "227";
            container.Type = MessageContainer.CommandTypes.Poll;
            container.Operation = MessageContainer.Operations.Acknownledgment;
            ViewData["__REQUEST"] = container.ToString();

            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult Login()
        {
            MessageContainer container = new MessageContainer();
            LoginMessage message = new LoginMessage();
            message.RegistrarID = "DEMO-REGISTRAR";
            message.Password = "14nov07";

            container.Command = message;
            container.Type = MessageContainer.CommandTypes.Login;
            ViewData["__REQUEST"] = container.ToString();

            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult LoginChangePassword()
        {
            MessageContainer container = new MessageContainer();
            LoginMessage message = new LoginMessage();
            message.RegistrarID = "DEMO-REGISTRAR";
            message.Password = "14nov07";
            message.NewPassword = "14mar64";

            container.Command = message;
            container.Type = MessageContainer.CommandTypes.Login;
            ViewData["__REQUEST"] = container.ToString();

            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult Logout()
        {
            MessageContainer container = new MessageContainer();
            container.Command = new LogoutMessage();
            container.Type = MessageContainer.CommandTypes.Logout;
            ViewData["__REQUEST"] = container.ToString();

            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult Hello()
        {
            MessageContainer container = new MessageContainer();
            container.Command = new HelloMessage();
            container.Type = MessageContainer.CommandTypes.Hello;
            ViewData["__REQUEST"] = container.ToString();

            SetBaseViewData();
            return View();
        }
    }
}
